<template>
	<view class="container999">
		<!-- <view class="bg"></view> -->
		<view class="card" v-for="(item,index) in 4" :style="{'z-index':nowIndex == index?10:-index}" :class="{ aniSmall:nowIndex+1 == index && !isNext , aniBig: nowIndex == index && isNext , aniNext:nowIndex-1 == index && isNext , aniBack:nowIndex == index && !isNext }"
		 :key="index">
			<view class="cardBottom">
				<block v-if="index==0">
					<view class="content_1 content">
						<view class="info-item">
							<view class="info">你的身高？</view>
							<view class="number">
								<view class="input-body">
									<input class="input" v-model="info.userHeight"></input>
									<text>CM</text>
								</view>
							</view>
						</view>
						<view class="info-item">
							<view class="info">你的性别？</view>
							<radio-group class="block" @change="RadioChange">
								<view class="cu-form-group margin-top sex">
									<view class="radio">
										<radio :class="info.userSex=='0'?'checked':''" :checked="info.userSex=='0'?true:false" value="0"></radio>
										<view class="title">男</view>
									</view>
									<view class="radio">
										<radio :class="info.userSex=='1'?'checked':''" :checked="info.userSex=='1'?true:false" value="1"></radio>
										<view class="title">女</view>
									</view>
								</view>
							</radio-group>
						</view>
					</view>
				</block>
				<block v-else-if="index==1">
					<view class="content_2 content">
						<view class="info-item">
							<view class="header shadow bg-white" @click="openBirthday">
								<view class="info">你的出生日期？</view>
								<view class="cotent">
									{{info.userBirthday||'请选择'}}
								</view>
							</view>
						</view>
					</view>
				</block>
				<block v-else-if="index==2">
					<view class="content_3 content">
						<view class="info-item">
							<view class="header shadow bg-white">
								<view class="info">现在体重？</view>
								<view class="cotent">
									{{info.userWeight||0}}<text class="tag-text">KG</text>
								</view>
							</view>
							<view class="choose">
								<scroll-choose @scroll="chooseNumberHander" :scrollLeft="info.userWeight"></scroll-choose>
							</view>
						</view>
					</view>
				</block>
				<block v-else-if="index==3">
					<view class="content_3 content">
						<view class="info-item">
							<view class="header shadow bg-white">
								<view class="info">目标体重？</view>
								<view class="cotent">
									{{info.userTargetWeight||0}}<text class="tag-text">KG</text>
								</view>
							</view>
							<view class="choose">
								<scroll-choose @scroll="chooseNumberHander" :scrollLeft="info.userTargetWeight"></scroll-choose>
							</view>
						</view>
					</view>
				</block>
			</view>
			<view class="btn back" @click="mBack">上一步</view>
			<view class="btn next" @click="mNext">{{nowIndex == 3?"提交报告":"下一步"}}</view>
		</view>
		<date-time ref="dateTime" :setDateTime="info.userBirthday" :type="2" @confirm="changeBirthday" :startYear="1900"></date-time>
	</view>
</template>

<script>
	import {
		throttle
	} from '../../util/common.js';
	import dateTime from '../../components/dateTime/dateTime.vue';
	import scrollChoose from '../../components/scroll-choose/scroll-choose.vue';
	export default {
		components: {
			dateTime,
			scrollChoose
		},
		data() {
			return {
				nowIndex: 0,
				isNext: true,
				info: {},
				userInfo: {}
			};
		},
		onLoad() {
			let userInfo = this.$store.getters.getUserInfo
			this.userInfo = userInfo
			let {
				userTargetWeight,
				userWeight,
				userSex,
				userHeight,
				userBirthday
			} = userInfo
			this.info = {
				userTargetWeight,
				userWeight,
				userSex,
				userHeight,
				userBirthday
			}
		},
		methods: {
			mNext: throttle(function(e) {
				if (this.nowIndex == 3) {
					this.$api.UpdateUserByIdInfo(this.info).then(res => {
						if (res.code) {
							this.userInfo = Object.assign(this.userInfo, this.info)
							this.$store.dispatch('setUserInfoAction', this.userInfo)
							this.$comm.switchTabTo("/pages/user/user",()=>{
								this.$comm.successToShow("修改成功")
							})
						}
					})
					return
				}
				this.isNext = true;
				this.nowIndex += 1
			}, 600),
			mBack: throttle(function(e) {
				if (this.nowIndex == 0) return
				this.isNext = false;
				this.nowIndex--;
			}, 600),
			openBirthday() {
				this.$refs.dateTime.show()
			},
			changeBirthday(e) {
				this.info.userBirthday = e.result
			},
			chooseNumberHander(e) {
				if (this.nowIndex == 2) {
					this.info.userWeight = e
				} else {
					this.info.userTargetWeight = e
				}
			},
			RadioChange(e) {
				this.info.userSex = e.detail.value
			}
		}
	};
</script>

<style lang="scss">
	.content {
		display: flex;
		flex-direction: column;
		align-items: center;
		margin-top: 30rpx;
		justify-content: space-around;
		height: 50vh;

		.info-item {
			display: flex;
			flex-direction: column;
			align-items: center;
		}
	}

	.content_2 {
		justify-content: flex-start;

		.header {
			padding: 20rpx 30rpx;
			padding-left: 80rpx;
			position: relative;
			left: -21px;

			.info {
				font-size: 22rpx;
				line-height: 30rpx;
			}

			.cotent {
				font-size: 40rpx;
				line-height: 80rpx;
			}



			border: 1rpx solid rgba($color: #000000, $alpha: 0.3);
			border-top-right-radius: 500upx;
			border-bottom-right-radius: 500upx;
			width: 70vw;
			display: flex;
			flex-direction: column;
			justify-content: center;
		}
	}


	.content_3 {
		justify-content: flex-start;

		.choose {
			overflow: hidden;
			margin-top: 130rpx;
			width: 520upx;
		}

		.header {
			padding: 20rpx 30rpx;
			position: relative;
			left: -21px;
			padding-left: 80rpx;

			.info {
				font-size: 22rpx;
				line-height: 30rpx;
			}

			.cotent {
				font-size: 40rpx;
				line-height: 80rpx;
			}

			.tag-text {
				font-size: 20rpx;
			}

			border: 1rpx solid rgba($color: #000000, $alpha: 0.3);
			border-top-right-radius: 500upx;
			border-bottom-right-radius: 500upx;
			width: 70vw;
			display: flex;
			flex-direction: column;
			justify-content: center;
		}
	}

	.content_1 {

		.info-item {
			display: flex;
			flex-direction: column;
			align-items: center;

			.sex {
				width: 50vw;
				display: flex;
				justify-content: space-around;

				.radio {
					display: flex;
					align-items: center;

					.title {
						margin-left: 10rpx;
					}
				}
			}

			.input-body {
				display: flex;
				align-items: flex-end;
				justify-content: center;

				.input {
					border: 1rpx solid rgba($color: #000000, $alpha: 0.3);
					background-color: #ffffff;
					height: 80rpx;
					line-height: 80rpx;
					border-radius: 900rpx;
					width: 280rpx;
					margin-right: 10rpx;
					text-align: center;
					font-size: 32rpx;
					margin-top: 50upx;
				}
			}
		}
	}

	.aniSmall {
		animation: aniSmall .6s both;

	}

	@keyframes aniSmall {
		0% {
			transform: scale(1);
		}

		95% {
			transform: scale(0.8);
		}
	}

	.aniBig {
		animation: aniBig .6s both;
	}

	@keyframes aniBig {
		0% {
			transform: scale(.8);
		}

		99% {
			transform: scale(1);
		}

		100% {
			transform: scale(1);
		}
	}

	.aniBack {
		animation: aniBack .6s both;
	}

	@keyframes aniBack {
		0% {
			z-index: 999;
			transform: translate(-120%, 50%) scale(.8) rotate(-30deg);
		}

		95% {
			z-index: 999;
			transform: translate(0, 0) scale(1) rotate(0);
		}

		96% {
			z-index: 999;
			transform: translate(0, 0) scale(1) rotate(0);
		}

		100% {
			z-index: 999;
			transform: translate(0, 0) scale(1) rotate(0);
		}
	}

	.aniNext {
		animation: aniNext .6s both;
	}

	@keyframes aniNext {
		0% {
			z-index: 999;
			transform: translate(0, 0) scale(1) rotate(0);
		}

		95% {
			z-index: 999;
			transform: translate(-130%, 50%) scale(.8) rotate(-30deg);
		}

		100% {
			z-index: 999;
			transform: translate(-130%, 50%) scale(.8) rotate(-30deg);
		}
	}

	.back {
		left: 78rpx;
	}

	.next {
		right: 78rpx;
	}

	.btn {
		position: absolute;
		bottom: 45rpx;
		width: 100rpx;
		height: 100rpx;
		display: flex;
		align-items: center;
		justify-content: center;
		font-size: 21rpx;
		font-weight: bold;
		color: rgba(9, 152, 220, 1);
	}

	.container999 {
		.bg {
			position: absolute;
			z-index: 9;
			top: 0;
			left: 0;
			width: 100vw;
			height: 16vh;
			background-color: #0998dc;
		}

		.card {
			.cardBottom {
				padding-top: 20rpx;

				.line {
					padding-top: 60rpx;
					width: 87%;
					position: relative;
					margin: auto;

					.lineBottom {
						font-size: 20rpx;
						color: #727272;
						padding-left: 72rpx;
					}

					.lineTop {
						.title {
							padding-left: 30rpx;
						}

						display: flex;
						align-items: center;
						justify-content: flex-start;

						.box {
							width: 31rpx;
							height: 31rpx;
							border: 1rpx solid rgba(9, 152, 220, 1);
							border-radius: 2rpx;
						}
					}
				}
			}

			.cardTop {
				padding-left: 60rpx;
				font-size: 29rpx;
				font-family: 'Microsoft YaHei';
				font-weight: bold;
				height: 14vh;
				background: linear-gradient(to bottom, #fefefe 0%, #f9d5bc);
				display: flex;
				align-items: center;
				justify-content: flex-start;
			}

			width: 80vw;
			position: absolute;
			top: 10vh;
			left: 0;
			right: 0;
			margin: auto;
			z-index: 10;
			height: 70vh;
			transition: .6s;
			overflow: hidden;
			transform: scale(.8);
			box-shadow: 0rpx 0rpx 17rpx 0rpx rgba(35, 36, 37, 0.25);
			background: rgba(254, 254, 254, 1);
			border-radius: 30rpx;
		}

		position: fixed;
		width: 100vw;
		height: 100vh;
		left: 0;
		top: 0;
	}
</style>
